package com.yunxin.core.application.assembler;

import com.yunxin.core.application.command.channel.*;
import com.yunxin.core.application.dto.channel.*;
import com.yunxin.core.domain.model.channel.*;
import com.yunxin.core.infra.persistence.entity.channel.*;
import com.yunxin.core.infra.persistence.entity.channel.query.condition.ChannelPageCondition;
import com.yunxin.core.infra.persistence.entity.channel.query.condition.ChannelPromotionPageCondition;
import com.yunxin.core.infra.persistence.entity.channel.query.condition.ChannelTypePageCondition;
import com.yunxin.core.infra.persistence.entity.channel.query.result.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * 渠道对象转换器
 * @author zero°
 * @since 2023-05-27
 */
@Mapper(componentModel = "spring")
public interface ChannelAssembler {

    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelAdvanceChargeRecordPageDTO
     */
    @Mapping(target = "advanceChargeDate", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateStr(entity.getAdvanceChargeDate()))")
    @Mapping(target = "settlementAmount", expression = "java(entity.getSettlementUnitPrice().multiply(new java.math.BigDecimal(entity.getSettlementNumber())))")
    ChannelAdvanceChargeRecordPageDTO toChannelAdvanceChargeRecordPageDTO(ChannelAdvanceChargeRecordDO entity);



    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelAdvanceChargeRecordDetailDTO
     */
    @Mapping(target = "advanceChargeDate", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateStr(entity.getAdvanceChargeDate()))")
    ChannelAdvanceChargeRecordDetailDTO toChannelAdvanceChargeRecordDetailDTO(ChannelAdvanceChargeRecordDO entity);


    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelPromotionApiCustomerConfigDTO
     */
    @Mapping(target = "cityConfigList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toStringList(entity.getCityConfig(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "beOverdueList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getBeOverdue(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "sexList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getSexes(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "sesameSeedQuotaList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getSesameSeedQuotas(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "antCreditPayQuotaList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getAntCreditPayQuotas(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "jdBtQuotaList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getJdBtQuotas(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "microLoanQuotaList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getMicroLoanQuotas(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "creditCardList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getCreditCards(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "educationLevelList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getEducationLevels(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "houseLevelList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getHouseLevels(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "vehicleLevelList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getVehicleLevels(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "accumulationFundLevelList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getAccumulationFundLevels(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "socialSecurityLevelList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getSocialSecurityLevels(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "insureList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getInsures(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "occupationList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getOccupations(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "occupationIncomeList", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.toIntegerList(entity.getOccupationIncomes(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    ChannelPromotionApiCustomerConfigDTO toChannelPromotionApiCustomerConfigDTO(ChannelPromotionApiCustomerConfigDO entity);

    /**
     * result 转 dto
     * @param result result
     * @return ChannelListDTO
     */
    ChannelListDTO toChannelListDTO(ChannelListResult result);

    /**
     * result 转 dto
     * @param result result
     * @return ChannelPageDTO
     */
    ChannelPageDTO toChannelPageDTO(ChannelInfoResult result);

    /**
     * result 转 dto
     * @param result result
     * @return ChannelDetailDTO
     */
    ChannelDetailDTO toChannelDetailDTO(ChannelInfoResult result);


    /**
     * result 转 dto
     * @param result result
     * @return ChannelPromotionPageDTO
     */
    @Mapping(target = "promotionTypeStr", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(result.getPromotionType(), com.yunxin.core.infra.common.channel.enums.PromotionTypeEnum.class))")
    @Mapping(target = "promotionStatusStr", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(result.getPromotionStatus(), com.yunxin.core.infra.common.channel.enums.PromotionStatusEnum.class))")
    @Mapping(target = "chargedWayStr", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(result.getChargedWay(), com.yunxin.core.utils.infra.common.enums.ChannelChargedWayTypeEnum.class))")
    ChannelPromotionPageDTO toChannelPromotionPageDTO(ChannelPromotionPageResult result);

    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelPromotionChargedListDTO
     */
    @Mapping(target = "chargedWayStr", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(entity.getChargedWay(), com.yunxin.core.utils.infra.common.enums.ChargedWayTypeEnum.class))")
    ChannelPromotionChargedListDTO toChannelPromotionChargedListDTO(ChannelPromotionUnitPriceConfigVersionDO entity);


    /**
     * result 转 dto
     * @param result result
     * @return ChannelPromotionChargedInfoDTO
     */
    @Mapping(target = "chargedWayStr", expression = "java(com.yunxin.common.base.IBaseEnum.getLabelByValue(result.getChargedWay(), com.yunxin.core.utils.infra.common.enums.ChargedWayTypeEnum.class))")
    ChannelPromotionChargedInfoDTO toChannelPromotionChargedInfoDTO(ChannelPromotionChargedInfoResult result);

    /**
     * result 转 dto
     * @param result result
     * @return ChannelPromotionInfoDTO
     */
    @Mapping(target = "loanPeriod", expression = "java(com.yunxin.common.utils.JacksonUtils.X.parse(result.getLoanPeriod(), new com.fasterxml.jackson.core.type.TypeReference<java.util.List<com.yunxin.core.application.dto.channel.ChannelPromotionInfoDTO.LoanPeriod>>() {}))")
    ChannelPromotionInfoDTO toChannelPromotionInfoDTO(ChannelPromotionDetailsResult result);

    /**
     * do 转 dto
     * @param channelPromotionCustomConfigDO channelPromotionCustomConfigDO
     * @return ChannelPromotionCustomInfoDTO
     */
    ChannelPromotionCustomInfoDTO toChannelPromotionCustomInfoDTO(ChannelPromotionCustomConfigDO channelPromotionCustomConfigDO);

    /**
     * result 转 dto
     * @param result result
     * @return ChannelPromotionBasicInfoDTO
     */
    ChannelPromotionBasicInfoDTO toChannelPromotionBasicInfoDTO(ChannelPromotionBasicInfoResult result);

    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelPromotionLinkConfigDTO
     */
    @Mapping(target = "loanPeriod", expression = "java(com.yunxin.common.utils.JacksonUtils.X.parse(entity.getLoanPeriod(), new com.fasterxml.jackson.core.type.TypeReference<java.util.List<com.yunxin.core.application.dto.channel.ChannelPromotionLinkConfigDTO.LoanPeriod>>() {}))")
    ChannelPromotionLinkConfigDTO toChannelPromotionLinkConfigDTO(ChannelPromotionLinkConfigDO entity);

    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelPromotionCustomConfigDTO
     */
    ChannelPromotionCustomConfigDTO toChannelPromotionCustomConfigDTO(ChannelPromotionCustomConfigDO entity);

    /**
     * entity 转 dto
     * @param entity entity
     * @return toChannelPromotionUnitPriceConfigDTO
     */
    ChannelPromotionUnitPriceConfigDTO toChannelPromotionUnitPriceConfigDTO(ChannelPromotionUnitPriceConfigDO entity);

    /**
     * result 转 dto
     * @param result result
     * @return ChannelTypeListDTO
     */
    ChannelTypeListDTO toChannelTypeListDTO(ChannelTypeListResult result);

    /**
     * entity 转 dto
     * @param entity entity
     * @return ChannelTypePageDTO
     */
    ChannelTypePageDTO toChannelTypePageDTO(ChannelTypeDO entity);



    /**
     * command 转 entity
     * @param command command
     * @return ChannelAdvanceChargeRecord
     */
    @Mapping(target = "advanceChargeDate", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateByStr(command.getAdvanceChargeDate()))")
    ChannelAdvanceChargeRecord fromAddChannelAdvanceChargeRecordCommand(AddChannelAdvanceChargeRecordCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelAdvanceChargeRecord
     */
    @Mapping(target = "advanceChargeDate", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateByStr(command.getAdvanceChargeDate()))")
    ChannelAdvanceChargeRecord fromUpdateChannelAdvanceChargeRecordCommand(UpdateChannelAdvanceChargeRecordCommand command);


    /**
     * command 转 condition
     * @param command entity
     * @return ChannelPromotionApiCustomerConfig
     */
    @Mapping(target = "cityConfig", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getCityConfigList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "beOverdue", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getBeOverdueList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "sexes", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getSexList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "sesameSeedQuotas", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getSesameSeedQuotaList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "antCreditPayQuotas", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getAntCreditPayQuotaList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "jdBtQuotas", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getJdBtQuotaList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "microLoanQuotas", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getMicroLoanQuotaList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "creditCards", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getCreditCardList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "educationLevels", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getEducationLevelList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "houseLevels", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getHouseLevelList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "vehicleLevels", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getVehicleLevelList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "accumulationFundLevels", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getAccumulationFundLevelList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "socialSecurityLevels", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getSocialSecurityLevelList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "insures", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getInsureList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "occupations", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getOccupationList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    @Mapping(target = "occupationIncomes", expression = "java(com.yunxin.core.utils.infra.utils.ConvertUtils.X.fromList(command.getOccupationIncomeList(), com.yunxin.core.utils.infra.common.constant.CommonConstants.COMMA))")
    ChannelPromotionApiCustomerConfig fromChannelPromotionApiCustomerConfigOperateCommand(ChannelPromotionApiCustomerConfigOperateCommand command);

    /**
     * command 转 condition
     * @param command command
     * @return ChannelCustomerApplyLibraryRecord
     */
    ChannelCustomerApplyLibraryRecord fromChannelCustomerApplyLibraryRecord(ChannelCustomerApplyLibraryCommand command);

    /**
     * command 转 condition
     * @param command command
     * @return ChannelPageCondition
     */
    ChannelPageCondition fromChannelPageCommand(ChannelPageCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelInfo
     */
    ChannelInfo formAddChannelCommand(AddChannelCommand command);


    /**
     * command 转 entity
     * @param command command
     * @return ChannelInfo
     */
    ChannelInfo formUpdateChannelCommand(UpdateChannelCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotion
     */
    ChannelPromotion fromAddChannelPromotionBasicInfoCommand(AddChannelPromotionBasicInfoCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotionBasicInfo
     */
    ChannelPromotionBasicInfo fromAddChannelPromotionBasicInfoCommandForBasicInfoCommand(AddChannelPromotionBasicInfoCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotion
     */
    @Mapping(target = "id", source = "promotionId")
    ChannelPromotion fromUpdateChannelPromotionBasicInfoCommand(UpdateChannelPromotionBasicInfoCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotionBasicInfo
     */
    ChannelPromotionBasicInfo fromUpdateChannelPromotionBasicInfoCommandForBasicInfoCommand(UpdateChannelPromotionBasicInfoCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotionLinkConfig
     */
    @Mapping(target = "loanPeriod", expression = "java(com.yunxin.common.utils.JacksonUtils.X.format(command.getLoanPeriod()))")
    ChannelPromotionLinkConfig fromChannelPromotionLinkConfigOperateCommand(ChannelPromotionLinkConfigOperateCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotionCustomConfig
     */
    ChannelPromotionCustomConfig fromChannelPromotionCustomConfigOperateCommand(ChannelPromotionCustomConfigOperateCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelPromotionUnitPriceConfig
     */
    @Mapping(target = "takeEffectTime", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateOrTimeByStr(command.getTakeEffectTime()))")
    ChannelPromotionUnitPriceConfig fromChannelPromotionUnitPriceConfigOperateCommand(ChannelPromotionUnitPriceConfigOperateCommand command);


    /**
     * command 转 condition
     * @param command command
     * @return ChannelPromotionPageCondition
     */
    ChannelPromotionPageCondition fromChannelPromotionPageCommand(ChannelPromotionPageCommand command);

    /**
     * command 转 condition
     * @param command command
     * @return ChannelTypePageCondition
     */
    ChannelTypePageCondition fromChannelTypePageCommand(ChannelTypePageCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelType
     */
    ChannelType formAddChannelTypeCommand(AddChannelTypeCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return ChannelType
     */
    ChannelType formUpdateChannelTypeCommand(UpdateChannelTypeCommand command);
}
